import BundleManager from "../core/BundleManager";
import ResManager from "../core/ResManager";
import SceneNavigator from "../core/SceneNavigator";

const { ccclass, property } = cc._decorator;

@ccclass
export default class Jewel extends cc.Component {

    @property({ type: cc.Sprite, tooltip: CC_DEV && '背景图' })
    public background: cc.Sprite = null;

    @property({ type: cc.Label, tooltip: CC_DEV && '游戏名' })
    public gameName: cc.Label = null;

    @property({ type: cc.Node, tooltip: CC_DEV && '更新节点' })
    public updateNode: cc.Node = null;

    @property({ type: cc.Sprite, tooltip: CC_DEV && '进度图' })
    public progressSp: cc.Sprite = null;

    @property({ type: cc.Label, tooltip: CC_DEV && '进度文本' })
    public progressLb: cc.Label = null;

    @property({ type: cc.Sprite, tooltip: CC_DEV && '下载图' })
    public downSp: cc.Sprite = null;

    @property({ type: cc.Sprite, tooltip: CC_DEV && '更新图' })
    public updateSp: cc.Sprite = null;

    data: any = null;

    init(data: any): void {
        this.data = data;
        let config_language = ResManager.ins().getRes('config_language');
        this.gameName.string = config_language[data.name] ? config_language[data.name].text : data.name;
    }

    onClick(): void {
        if(this.data.path){
            BundleManager.ins().loadBundle('bundles/'+this.data.name,`scene/${this.data.name}Scene`,(scene)=>{
                cc.director.runScene(scene);
            })
        }else{
            SceneNavigator.go(this.data.name + 'Scene', {});
        }
    }

}